package extrace.loader;

import android.app.Activity;
import android.util.Log;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.google.gson.reflect.TypeToken;

import java.util.List;

import extrace.misc.model.ExpressHistory;
import extrace.misc.model.Rp;
import extrace.misc.model.TransPackage;
import extrace.net.HttpAsyncTask;
import extrace.net.HttpResponseParam.RETURN_STATUS;
import extrace.net.IDataAdapter;
import extrace.net.JsonUtils;
import extrace.ui.domain.ExpressHistoryAdapter;
import extrace.ui.main.ExTraceApplication;

public class ExpressHistoryLoader extends HttpAsyncTask {

	String url;
	int uid;
	IDataAdapter<List<ExpressHistory>> adapter;
	private Activity context;

	public ExpressHistoryLoader(IDataAdapter<List<ExpressHistory>> adpt, Activity context) {
		super(context);
		this.context = context;
		adapter = adpt;
		url = ((ExTraceApplication)context.getApplication()).getDomainServiceUrl();
		uid=((ExTraceApplication)context.getApplication()).getLoginUser().getUID();
	}

	@Override
	public void onDataReceive(String class_name, String json_data) {

	}

	@Override
	public void onDataReceive(String json_data) {
		List<ExpressHistory> list= JSON.parseArray(json_data,ExpressHistory.class);
		//List<ExpressHistory> list= JsonUtils.fromJson(json_data,new TypeToken<List<ExpressHistory>>(){});
		Log.i("TAG", "onDataReceive: "+list.toString());
		adapter.setData(list);
		adapter.notifyDataSetChanged();

	}

	@Override
	public void onStatusNotify(RETURN_STATUS status, String str_response) {
		// TODO Auto-generated method stub
		
	}
	public void getHistory(String id) {
		url += "getExpressHistoryList/"+id+"?_type=json";
		try {
			execute(url, "GET");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
